package com.ahuan.exception;


import com.ahuan.resp.Res;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler extends ResponseEntityExceptionHandler {

    @ExceptionHandler(BusinessException.class)
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public Res handlerBusinessException(BusinessException e){
        log.error("业务异常:{}",e.getMessage());
        return Res.error();
    }

    @ExceptionHandler(InterceptorException.class)
    public Res handleException(InterceptorException e) {
        // 在这里编写处理异常的逻辑
        // 返回适当的响应，比如错误消息或者错误页面
        log.error("拦截器异常:{},详细信息如下：\n",e.getMessage());
        return Res.error();
    }

}
